package dotdashdot.bradz.trendsettr;

import java.sql.Timestamp;
import java.util.ArrayList;

import org.apache.commons.lang3.StringUtils;

import android.util.Log;

//This is basically a container for the trends
public class ClassTopic {
	private int primary;
	private String name;
	private ArrayList<ClassTrend> trends;
	private ClassUberLogger logger;

	ClassTopic(String name, ArrayList<ClassTrend> trend){
		this.name = name;
		this.trends = new ArrayList<ClassTrend>(trend);
		logger = new ClassUberLogger("ClassTopic");
	}
	public int get_primary(){
		return primary;
	}
	
    public int find_uniqueness(String word1, String word2){
    	return StringUtils.getLevenshteinDistance(word1, word2);
    }
	
    public boolean close_to_trend(String new_trend, int closeness){ 
    	logger.info("Checking for trend closeness...");
    	for(ClassTrend trend:trends){
    		logger.info("Comparing: " + new_trend + " - " + trend.get_name());
			if(find_uniqueness(trend.get_name().toLowerCase(),new_trend.toLowerCase()) <= closeness){
				logger.info("Found Match!");
				return true;
			}
		}
		return false;
    }
    
	public boolean contains_trend(String new_trend){
		logger.info("Checking for trend");
		for(ClassTrend trend:trends){
			logger.info("Comparing: " + new_trend + " - " + trend.get_name());
			if(trend.get_name().toLowerCase().equals(new_trend.toLowerCase())){
				logger.info("Found Match!");
				return true;
			}
		}
		return false;
	}
	public ArrayList<ClassTrend> get_trend(){
		return trends;
	}
	public String get_name(){
		return name;
	}
	public ArrayList<ClassTrend> get_unused_trends(){
		ArrayList<ClassTrend> new_trend_list = new ArrayList<ClassTrend>();
		logger.info("Checking for unused trends");
		for(ClassTrend ind_trend:trends){
			if(ind_trend.get_info().vote != -1 && ind_trend.get_info().vote != 1){
				logger.info("Found Unused Trend: " + ind_trend.get_name());
				new_trend_list.add(ind_trend);
			}
		}
		return new_trend_list;
	}
	public void add_trend(String picture, String name, String meta_summary, String link, int total, int ups, Timestamp created){
		ClassTrend new_trend = new ClassTrend(picture, name, meta_summary, link);
		new_trend.get_info().total = total;
		new_trend.get_info().ups = ups;
		new_trend.get_info().date_created = created;
		logger.info("Adding trend...");
		if(!trends.contains(new_trend)){
			logger.info("Trend added!");
			trends.add(new_trend);
		}else{
			logger.info("Trend already exists");
		}
	}
	public void add_trend(String picture, String name, String meta_summary, String link, int total, int ups, int vote, Timestamp created){
		ClassTrend new_trend = new ClassTrend(picture, name, meta_summary, link);
		new_trend.get_info().total = total;
		new_trend.get_info().ups = ups;
		new_trend.get_info().vote = vote;
		new_trend.get_info().date_created = created;
		logger.info("Adding trend...");
		if(!trends.contains(new_trend)){
			logger.info("Trend added!");
			trends.add(new_trend);
		}else{
			logger.info("Trend already exists");
		}
	}

}
